home *** CD-ROM | disk | FTP | other *** search
/ Wildcat Files 2 / The Wildcat Files 2 (Arsenal Computer).ISO / wildcat / wcfaxdb.pas < prev    next >
Pascal/Delphi Source File  |  1994-06-14  |  10KB  |  333 lines

  1. {$I WCDEFINE.INC}
  2. {RESPONSIBILITY SLR}
  3. unit WCFAXDB;
  4.  
  5. interface
  6.  
  7. uses
  8.   Dos,
  9. {$IFDEF OPRO}
  10.   OpDos,
  11.   OPDate,
  12.   OpString,
  13. {$ELSE}
  14.   TpDos,
  15.   TpDate,
  16.   TpString,
  17. {$ENDIF}
  18.   WcType,
  19.   WcErr,
  20.   IsamTool,
  21.   Filer,
  22.   NumKeys,
  23.   WcGlobal,
  24.   WCDB;
  25.  
  26. const
  27.   MaxBusies   = 5;
  28.   MaxErrors   = 3;
  29.  
  30.   FAXCreateTimeKey = 1;
  31.   FAXToFAXNumber   = 2;
  32.   FAXUserNameKey   = 3;
  33.   FAXSentTimeKey   = 4;
  34.   FAXStatusKey     = 5;
  35.  
  36. type
  37.   Str12 = String[12];
  38.   Str19 = String[19];
  39.   Str25 = String[25];
  40.   Str20 = String[20];
  41.  
  42.   TFaxType = (ftLocal, ftMetro, ftRegional, ftLDistance, ftOSeas);
  43.  
  44.   TFaxPhoneRec = record
  45.      AreaCode : String[3];
  46.      StNumber : String[20];
  47.      EndNumber : String[20];
  48.      Location : String[19];
  49.      NumberType : TFaxType;
  50.   end;
  51.  
  52.   {---------------------------}
  53.  
  54.   TFaxStatus             = (fsPending,
  55.                             fsSending,
  56.                             fsSent,
  57.                             fsError,
  58.                             fsNotSent,
  59.                             fsVoice,
  60.                             fsBusy);  {Status of job}
  61.  
  62.   TFaxDocumentList   = array[1..99] of String[20]; {Actual document names pending}
  63.  
  64.   PFaxRec = ^TFaxRec;
  65.   TFaxRec = record
  66.     Del          : LongInt;
  67.     LocalId      : String[20];       {Node Name, Sysop Name}
  68.     ToSystem     : String[27];       {To Company etc.}
  69.     ToName       : String[30];       {To Name of person}
  70.     ToNumber     : String[19];       {To Fax Number}
  71.     FromSystem   : String[27];       {From SystemName}
  72.     FromName     : String[30];       {From User Name}
  73.     Subject      : String[30];       {Subject of FAX}
  74.     DialString   : String;           {To Fax Number with Prefix etc...}
  75.     FaxType      : TFaxType;         {Destination type}
  76.     CreateDate   : DateTimeRec;      {Create Date & Time}
  77.     SentDate     : DateTimeRec;      {Sent Date & Time}
  78.     Documents    : TFaxDocumentList; {Document List}
  79.     RasFileName  : String[12];       {Rasterized file name}
  80.     DialAttempts : Byte;             {Dial Attempts}
  81.     SendAttempts : Byte;             {Send Attempts}
  82.     Status       : TFaxStatus;       {Status of FAX document}
  83.     TotalPages   : Word;             {Total pages of fax}
  84.     TotalCost    : LongInt;          {Total cost of document}
  85.     Fine         : Boolean;
  86.     MsgBytes     : Word;             {Total Number of characters in Message}
  87.     ToId         : LongInt;          {UserId of person to send to}
  88.     OrigNodeId   : Byte;             {Originators Node Id for create key}
  89.     Filler       : array[1..95] of Byte;  {Nada}
  90.   end;
  91.  
  92.   {----------------------}
  93.  
  94.   TDocArray = Array [1..10] of PathStr;
  95.  
  96.   TFAXListRec = record                  {WCFAX.LST}
  97.     Name : String[20];                  {Name of Document}
  98.     Desc : String[75];                  {Description of Document}
  99.     Doc : TDocArray;                    {Array of paths to docs}
  100.     TotalPages : Word;                  {Total pages of Document}
  101.     CreationDate : Date;                {Creationdate}
  102.     TimesSent : Word;                   {Times document save}
  103.     Cost : LongInt;                     {Cost by send type}
  104.     Secs : TArray1000Bits;              {Security Level Bits}
  105.   end;
  106.  
  107.   {----------------------}
  108. const
  109.   dSunday     = $01;
  110.   dMonday     = $02;
  111.   dTuesday    = $04;
  112.   dWednesday  = $08;
  113.   dThursday   = $10;
  114.   dFriday     = $20;
  115.   dSaturday   = $40;
  116.  
  117. type
  118.   TFaxSpec = record
  119.     Prefix : String[20];                  {String sent before the number}
  120.     Suffix : String[20];                  {String sent after the number}
  121.     StartTime,                            {Time to start processing these faxes}
  122.     EndTime : Time;                       {Time to end processing these faxes}
  123.     Days : Byte;                          {Days of week that we process these faxes}
  124.   end;
  125.  
  126.   TFaxTypeArray = array[TFaxType] of TFaxSpec;
  127.  
  128.   TFAXConfig = Record     {WCFAX.CFG}
  129.     WCFAXPath           : PathStr;     {Location of WCFAX files}
  130.     OriginalPath        : PathStr;     {Location of Raw documents}
  131.     PendingPath         : PathStr;     {Location of Rasterized files}
  132.     FaxCoverPath        : PathStr;     {Cover page path and filename}
  133.     ConferenceNum       : Word;        {Conference where messages sent}
  134.     InternationalMode   : Boolean;     {Use Free form phone numbers}
  135.     Status              : Boolean;     {Display status during FAX Send}
  136.     {Following is stuff pertaining to the Server sending Faxes}
  137.     SBaud               : LongInt;      {FAXSERVERs FAX baud rate}
  138.     SLastAttemptBaud    : LongInt;      {FAXSERVERs Last attempt FAX baud rate}
  139.     SPreDial            : String[20];   {PreDial command goes before dial prefix}
  140.     SDialCommand        : String[20];   {Servers dial commmand i.e. ATDT}
  141.     SecuritySpecifics   : TFaxTypeArray;{Fax specifics regarding time of day etc}
  142.   end;
  143.  
  144. {Flags for the WCFAX.SEC file}
  145. const
  146.   fsFAXFineMode   = $0001;
  147.   fsFAXViewMode   = $0002;
  148.   fsFAXSysopMode  = $0004;
  149.   fsFAXChangeName = $0008;
  150.   fsFAXEditor     = $0010;
  151.   ntOverSeas      = $0020;
  152.   ntLongDistance  = $0040;
  153.   ntRegional      = $0080;
  154.   ntMetro         = $0100;
  155.   ntLocal         = $0200;
  156.  
  157.   {----------------------}
  158. type
  159.   PFaxDatabase = ^TFaxDatabase;
  160.   TFAXDatabase = object(TFileBlock)
  161.     constructor Init;
  162.     destructor Done; virtual;
  163.     function DataLen(const Data) : Word; virtual;
  164.     procedure GetCreateInfo(var Len : Word; var Keys : Integer; var IID : IsamIndDescr); virtual;
  165.     function BuildKey(const Data; Key : Integer) : IsamKeyStr; virtual;
  166.     procedure UpdateRec(var NewFaxRec);
  167.     procedure DeleteRecordPrim(RefNr : LongInt; var Data); virtual;
  168.     procedure DeleteRasterizedFile(FN : Str12);
  169.     function BuildCreateTimeKey(CreateDate : DateTimeRec; OrigNodeId : Byte) : IsamKeystr;
  170.     function BuildToFaxNumberKey(Num : Str19) : IsamKeyStr;
  171.     function BuildUserNameKey(Name : Str25) : IsamKeyStr;
  172.     function BuildSentTimeKey(SentTime : DateTimeRec; Status : TFaxStatus) : IsamKeyStr;
  173.     function BuildStatusKey(Status : TFaxStatus) : IsamKeyStr;
  174.   end;
  175.  
  176.  
  177. const
  178.   FaxInitialized : Boolean = False;
  179.  
  180. var
  181.   Config : TFaxConfig;
  182.   FaxDb : TFaxDatabase;
  183.  
  184. implementation
  185.  
  186.   constructor TFAXDatabase.Init;
  187.   begin
  188.     with MwConfig do
  189.       begin
  190.         if not inherited Init(AddBackSlash(Config.WcFaxPath)+'WCFAX',
  191.                               DatabaseMode = dbSaveMode,
  192.                               Network <> WcType.NoNet,
  193.                               FaxCreateTimeKey,
  194.                               SizeOf(TFaxRec)) then
  195.           Fail;
  196.       end;
  197.     FaxInitialized := True;
  198.   end;
  199.  
  200.   destructor TFaxDatabase.Done;
  201.   begin
  202.     FaxInitialized := False;
  203.     inherited Done;
  204.   end;
  205.  
  206.  
  207.   function TFaxDatabase.DataLen(const Data) : Word;
  208.   var
  209.     F : TFaxRec;
  210.  
  211.   begin
  212.     DataLen := SizeOf(TfaxRec);
  213.   end;
  214.  
  215.  
  216.   procedure TFAXDatabase.GetCreateInfo(var Len : Word; var Keys : Integer; var IID : IsamIndDescr);
  217.   begin
  218.     Len := SizeOf(TFaxRec);
  219.     Keys := 5;
  220.     IID[FAXCreateTimeKey].KeyL          := 8;
  221.     IID[FAXCreateTimeKey].AllowDupK     := False;
  222.     IID[FaxToFAXNumber].KeyL            := 20;
  223.     IID[FAXToFAXNumber].AllowDupK       := True;
  224.     IID[FAXUserNameKey].KeyL            := 25;
  225.     IID[FaxUserNameKey].AllowDupK       := True;
  226.     IID[FaxSentTimeKey].KeyL            := 6;
  227.     IID[FaxSentTimeKey].AllowDupK       := True;
  228.     IID[FaxStatusKey].KeyL              := 1;
  229.     IID[FaxStatusKey].AllowDupK         := True;
  230.   end;
  231.  
  232.  
  233.   function TFaxDataBase.BuildKey(const Data; Key : Integer) : IsamKeyStr;
  234.   var
  235.     FaxRec : TFaxRec absolute Data;
  236.  
  237.   begin
  238.     with FAXRec do
  239.       case Key of
  240.         FAXCreateTimeKey : BuildKey := WordToKey(OrigNodeId)+
  241.                                        WordToKey(CreateDate.D)+
  242.                                        LongToKey(CreateDate.T);
  243.         FAXToFAXNumber : BuildKey := ToNumber;
  244.         FAXUserNameKEy : BuildKey := FromName;
  245.         FAXSentTimeKEy : if Status <> fsSent then
  246.                            BuildKey := ''
  247.                          else
  248.                            BuildKey := WordToKey(SentDate.D) +
  249.                                        LongToKey(SentDate.T);
  250.         FAXStatusKey : BuildKey := Long2Str(Ord(Status));
  251.       end;
  252.   end;
  253.  
  254.  
  255.   procedure TFaxDatabase.UpdateRec(var NewFaxRec);
  256.   var
  257.     RefNr : LongInt;
  258.     OldHeader : TFaxRec;
  259.  
  260.   begin
  261.     Lock;
  262.     if FindKey(FaxUserNameKey, RefNr, BuildKey(NewFaxRec, FaxUserNameKey)) then
  263.       begin
  264.         GetRec(RefNr, OldHeader);
  265.         if IsamOk then
  266.           PutRecordPrim(RefNr, OldHeader, NewFaxRec);
  267.       end;
  268.     Unlock;
  269.   end;
  270.  
  271.  
  272.   procedure TFaxDatabase.DeleteRecordPrim(RefNr : LongInt; var Data);
  273.   var
  274.     F : File;
  275.     Io : Word;
  276.     FaxRec : TFaxRec absolute Data;
  277.  
  278.   begin
  279.     inherited DeleteRecordPrim(RefNr, Data);
  280.     if FaxRec.RasFileName <> '' then
  281.       begin
  282.         DeleteRasterizedFile(FaxRec.RasFileName);
  283.         DeleteRasterizedFile(FaxRec.RasFileName + '.RAS');
  284.       end;
  285.   end;
  286.  
  287.  
  288.   procedure TFaxDataBase.DeleteRasterizedFile(Fn : Str12);
  289.   var
  290.     f : file;
  291.     Io : Word;
  292.  
  293.   begin
  294.     if ExistFile(AddBackSlash(Config.PendingPath)+FN) then begin
  295.       Assign(f, AddBackSlash(Config.PendingPath)+Fn);
  296.       Erase(f);
  297.       Io := IoResult;
  298.       if Io <> 0 then
  299.         LogIoError('Unable to delete rasterized file. ' + Fn, Io);
  300.     end;
  301.   end;
  302.  
  303.   function TFAxDataBase.BuildCreateTimeKey(CreateDate : DateTimeRec; OrigNodeId : Byte) : IsamKeystr;
  304.   begin
  305.     BuildCreateTimeKey := WordToKey(OrigNodeId)+
  306.                           WordToKey(CreateDate.D)+
  307.                           LongToKey(CreateDate.T);
  308.   end;
  309.  
  310.   function TFaxDatabase.BuildToFaxNumberKey(Num : Str19) : IsamKeyStr;
  311.   begin
  312.     BuildToFaxNumberKey := Num;
  313.   end;
  314.  
  315.   function TFaxDatabase.BuildUserNameKey(Name : Str25) : IsamKeyStr;
  316.   begin
  317.     BuildUserNameKey := Name;
  318.   end;
  319.  
  320.   function TFaxDatabase.BuildSentTimeKey(SentTime : DateTimeRec; Status : TFaxStatus) : IsamKeyStr;
  321.   begin
  322.     if Status <> fsSent then
  323.       BuildSentTimeKey := ''
  324.     else
  325.       BuildSentTimeKey := WordToKey(SentTime.D) + LongToKey(SentTime.T);
  326.   end;
  327.  
  328.   function TFaxDatabase.BuildStatusKey(Status : TFaxStatus) : IsamKeyStr;
  329.   begin
  330.     BuildStatusKey := Long2Str(Ord(Status));
  331.   end;
  332.  
  333. end.